package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Email {

    public static void main(final String[] args) {

        // For prefix
        String prefix_pattern = "([a-zA-Z0-9]+[-_\\.]?)*[a-zA-Z0-9]+";
        Pattern compile = Pattern.compile(prefix_pattern);

        String string = "a";
        Matcher matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "1";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a1";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "_d";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a_";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a_.d";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a_b.c-d";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a-b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        // For mail
        String pattern = "([a-zA-Z0-9]+[-_\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[-_]?)+[a-zA-Z0-9]+(\\.[a-zA-Z]{2,4})(\\.[a-zA-Z]{2})?";
        compile = Pattern.compile(pattern);

        string = "aaaaaaa";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "11231231";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        // For suffix
        string = "a@bb.c";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a@bb.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a@bb.ccc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a@bb.cn";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a@bb.cc.cn";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        // For domain
        string = "abc@b.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abcb@0.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@a1.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@1a.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@a-b.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@a_b.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@a_-b.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@a_.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc@_b.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));
    }
}
